<%--suppress JSJQueryEfficiency --%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css"
          href="../../../js/jquery-easyui-1.9.5/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css"
          href="../../../js/jquery-easyui-1.9.5/themes/icon.css">
    <link rel="stylesheet" type="text/css"
          href="../../../js/jquery-easyui-1.9.5/themes/color.css">
    <script type="text/javascript"
            src="../../../js/jquery-easyui-1.9.5/jquery.min.js"></script>
    <script type="text/javascript"
            src="../../../js/jquery-easyui-1.9.5/jquery.easyui.min.js"></script>
</head>
<body>
<table id="volunteerActivity_dg" title="活动信息" class="easyui-datagrid" style="width:100%;height:100%"
       url="../volunteerActivity/list"
       toolbar="#volunteerActivity_toolbar"
       rownumbers="true" pagination="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="activityNo" style="width: 16%">活动编号</th>
        <th field="activityName" style="width: 16%">活动名称</th>
        <th field="activityTheme" style="width: 16%">活动主题</th>
        <th field="activityDate" style="width: 16%">活动时间</th>
        <th field="activityNum" style="width: 16%">活动人数</th>
        <th field="activityLocation" style="width: 16%">活动地点</th>
    </tr>
    </thead>
</table>

<div id="volunteerActivity_toolbar">
    <label for="searchActivityNameVolunteerActivity">活动名称:</label>
    <input id="searchActivityNameVolunteerActivity" name="activityName" type="text" class="easyui-textbox"/>
    <a id="search" href="javascript:doVolunteerActivitySearch();" class="easyui-linkbutton"
       data-options="iconCls:'icon-search'">Search</a>
    <a id="reset" href="javascript:doVolunteerActivityReset();" class="easyui-linkbutton"
       data-options="iconCls:'icon-redo'">Reset</a>
    <br/>
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
       onclick="newVolunteerActivity()">New volunteerActivity</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true"
       onclick="editVolunteerActivity()">Edit volunteerActivity</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true"
       onclick="destroyVolunteerActivity()">Remove volunteerActivity</a>
</div>

<%--        新增和修改对话框--%>
<div id="volunteerActivity_dlg" class="easyui-dialog" style="width:400px;height:500px;padding:10px 20px"
     closed="true" buttons="#volunteerActivity_dlg-buttons">
    <div class="ftitle" style="text-align: center">volunteerActivity Message</div>
    <br>
    <form id="volunteerActivity_fm" method="post">
        <div class="fitem">
            <label for="activityName">活动名称&emsp;</label>
            <input id="activityName" name="activityName" class="easyui-textbox"
                   data-options="required:true,missingMessage:'activityName is not null'"
                   prompt="name" style="width: 250px">
        </div>
        <br>
        <div class="fitem">
            <label for="activityTheme">活动主题&emsp;</label>
            <input id="activityTheme" name="activityTheme" class="easyui-textbox"
                   data-options="required:true,missingMessage:'activityTheme is not null'"
                   prompt="activityTheme" style="width: 250px">
        </div>
        <br>
        <div class="fitem">
            <label for="activityDate">活动时间&emsp;</label>
            <input id="activityDate" name="activityDate" class="easyui-datetimebox"
                   data-options="required:true,missingMessage:'activityDate is not null',
                           showSeconds:true,formatter:formatter,parser:parser" style="width: 250px">
        </div>
        <br>
        <div class="fitem">
            <label for="activityNum">活动人数&emsp;</label>
            <input id="activityNum" name="activityNum" class="easyui-textbox"
                   prompt="activityNum" style="width: 250px">
        </div>
        <br>
        <div class="fitem">
            <label for="activityLocation">活动地点&emsp;</label>
            <input id="activityLocation" name="activityLocation" class="easyui-textbox"
                   prompt="activityLocation" style="width: 250px">
        </div>
    </form>
</div>

<div id="volunteerActivity_dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok"
       onclick="saveVolunteerActivity()">Save</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel"
       onclick="$('#volunteerActivity_dlg').dialog('close')">Cancel</a>
</div>

<script type="text/javascript">
    //框架进阶：1.能使用框架，2.能扩展框架，3.能修改框架，4.能设计框架
    //修改easyUI组件的时间格式-时间格式化器-把时间对象转换为字符串
    function formatter(date) {
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();
        let hour = date.getHours().toString();
        let minutes = date.getMinutes().toString();
        let seconds = date.getSeconds().toString();
        month = month < 10 ? '0' + month : month;
        day = day < 10 ? '0' + day : day;
        hour = hour < 10 ? '0' + hour : hour;
        minutes = minutes < 10 ? '0' + minutes : minutes;
        seconds = seconds < 10 ? '0' + seconds : seconds;
        return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds;
    }

    //时间解析器：把字符串转换为javascript的时间对象
    function parser(s) {
        let t = Date.parse(s);
        if (!isNaN(t)) {
            return new Date(t);
        } else {
            return new Date(s + ":00:00");
        }
    }

    function doVolunteerActivitySearch() {
        $("#searchActivityNameVolunteerActivity").textbox('setValue', $("#searchActivityNameVolunteerActivity").val().trim());
        //调用datagrid对象的load方法查询数据，并传递查询参数
        $("#volunteerActivity_dg").datagrid("load", {
            "activityName": $("#searchActivityNameVolunteerActivity").val(),
        });
    }

    function doVolunteerActivityReset() {
        $("#searchActivityNameVolunteerActivity").textbox('setValue', '');
        //清空查询参数后，重新加载数据
        $("#volunteerActivity_dg").datagrid("load", {});
    }

    function newVolunteerActivity() {
        $('#volunteerActivity_dlg').dialog('open').dialog('setTitle', 'New VolunteerActivity');
        $('#volunteerActivity_fm').form('clear');
        url = '../volunteerActivity/add';
        const d = new Date();
        const nowDate = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() +
            " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
        $('#activityDate').datetimebox('setValue', nowDate);
    }

    function editVolunteerActivity() {
        $('#volunteerActivity_fm').form('clear');
        var row = $('#volunteerActivity_dg').datagrid('getSelected');
        if (row) {
            $('#volunteerActivity_dlg').dialog('open').dialog('setTitle', 'Edit VolunteerActivity');
            $('#volunteerActivity_fm').form('load', row);
            url = '../volunteerActivity/edit?activityNo=' + row.activityNo;
        } else {
            $.messager.show({
                title: 'Error',
                msg: "请选择要修改的用户信息"
            });
        }
    }

    function destroyVolunteerActivity() {
        var row = $('#volunteerActivity_dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('Confirm', '是否需要删除该信息？', function (r) {
                if (r) {
                    $.post('../volunteerActivity/delete', {activityNo: row.activityNo}, function (result) {
                        if (result.success) {
                            $('#volunteerActivity_dg').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        }
                    }, 'json');
                }
            });
        } else {
            $.messager.show({
                title: 'Error',
                msg: "请选择要删除的用户信息"
            });
        }
    }

    function saveVolunteerActivity() {
        $('#volunteerActivity_fm').form('submit', {
            url: url,
            onSubmit: function () {
                // 提交表单前 表单验证
                return $(this).form('validate');
            },
            success: function (result) {
                // 收到服务器响应的json字符串后，调用这里的代码，回调函数当浏览器收到服务器返回的数据后才执行
                var result = eval('(' + result + ')');
                if (!result.success) {
                    $.messager.show({
                        title: 'Error',
                        msg: result.errorMsg
                    });
                } else {
                    $('#volunteerActivity_dlg').dialog('close');		// 新增成功，关闭对话框
                    $('#volunteerActivity_dg').datagrid('reload');	// 新增成功，刷新列表数据
                }
            }
        });
    }
</script>
</body>
</html>
